<?php echo $error; ?>
<div class="flexigrid">
    <div class="mDiv">
        <div class="ftitle">
            &nbsp;
        </div>
        <div title="Minimize/Maximize" class="ptogtitle">
            <span></span>
        </div>
    </div>
    <div id="main-table-box">
        <div class="tDiv tDiv4">
            <div class="row">
                <div class="large-12 columns centered">
                    <?php echo validation_errors('<p class="alert label">'); ?>
                    <form action="agregarVehiculo" method="post" class="custom" enctype="multipart/form-data">
                        <table class="responsive">
                            <!--<input type="hidden" name="verdadero" value="n">
                            <input name="Fecha_Subasta" type="hidden" value="1">
                            <input type="hidden" name="Lote" value="nr">
                            <input type="hidden" name="Emblema" value="nr">-->
                            <tbody>
                                <tr>
                                    <td>Carroceria:</td>
                                    <td>
                                        <?php
                                        if (isset($_GET['c'])) {
                                            $carrocerias = $_GET['c'];
                                        } else {
                                            $carrocerias = 1;
                                        }
                                        ?>
                                        <select id="carroceria" name="carroceria_id">
                                            <?php
                                            foreach ($carroceria as $row) {
                                                if ($carrocerias == $row->id) {
                                                    echo '<option value="' . $row->id . '" selected>' . $row->tipo . '</option>';
                                                } else {
                                                    echo '<option value="' . $row->id . '">' . $row->tipo . '</option>';
                                                }
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td>Tipo:</td>
                                    <td>
                                        <select name="tipo">
                                            <?php
                                            foreach ($tipo as $row) {
                                                echo '<option value="' . $row->tipo . '">' . $row->tipo . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Marca:</td>
                                    <td>
                                        <select name="marca">
                                            <?php
                                            foreach ($marcas as $row) {
                                                echo '<option value="' . $row->marca . '">' . $row->marca . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td>Modelo:</td>
                                    <td><input type="text" name="modelo"></td>
                                </tr>
                                <tr>
                                    <td>Transmision:</td>
                                    <td>
                                        <select name="transmision">
                                            <?php
                                            foreach ($transmision as $row) {
                                                echo '<option value="' . $row->tipo . '">' . $row->tipo . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td>Categoria:</td>
                                    <td>
                                        <select name="categoria">
                                            <?php
                                            foreach ($categorias as $row) {
                                                echo '<option value="' . $row->categoria . '">' . $row->categoria . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Combustible:</td>
                                    <td>
                                        <select name="combustible">
                                            <?php
                                            foreach ($combustibles as $row) {
                                                echo '<option value="' . $row->combustible . '">' . $row->combustible . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td>Año:</td>
                                    <td>
                                        <select name="anno">
                                            <?php
                                            for ($i = 2013; $i >= 1980; $i--) {
                                                echo '<option>' . $i . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Precio:</td>
                                    <td>
                                        <select name="precio">
                                            <?php
                                            foreach ($precios as $row) {
                                                echo '<option value="' . $row->precio . '">$' . $row->precio . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                    <td>Cilindrada:</td>
                                    <td>
                                        <select name="cilindrada">
                                            <?php
                                            foreach ($cilindrada as $row) {
                                                echo '<option value="' . $row->cilindrada . '">' . $row->cilindrada . 'cc</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>Kilometraje:</td>
                                    <td><input type="text" name="kilometraje"></td>
                                    <td>Color Exterior:</td>
                                    <td>
                                        <select name="color_exterior">
                                            <?php
                                            foreach ($colores as $row) {
                                                echo '<option value="' . $row->color . '">' . $row->color . '</option>';
                                            }
                                            ?>
                                        </select>
                                    </td>
                                </tr>
                                <?php if ($carrocerias != 2 && $carrocerias != 3): ?>
                                    <tr class="vehiculo">
                                        <td>Color Interior:</td>
                                        <td>
                                            <select name="color_interior">
                                                <?php
                                                foreach ($colores as $row) {
                                                    echo '<option value="' . $row->color . '">' . $row->color . '</option>';
                                                }
                                                ?>
                                            </select>
                                        </td>
                                        <td>Puertas:</td>
                                        <td>
                                            <select name="puertas">
                                                <?php
                                                for ($i = 2; $i < 5; $i++) {
                                                    echo '<option>' . $i . '</option>';
                                                }
                                                ?>
                                            </select>
                                        </td>
                                    </tr>

                                    <tr class="vehiculo">
                                        <td colspan="4">
                                            Extras:
                                            <div class="row">
                                                <div class="large-12 columns">
                                                    <label><input type="checkbox" class="check small button secondary radius" /> Marcar todas</label>
                                                </div>
                                                <div id="extras">
                                                    <?php foreach ($extras as $row) : ?>
                                                        <div class="large-3 columns">
                                                            <label><input type="checkbox" name="<?php echo $row->input_name; ?>" class="extras">
                                                                <?php echo $row->extra; ?></label>
                                                        </div>
                                                    <?php endforeach; ?>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                <?php endif; ?>
                                <tr>
                                    <td colspan="2"><strong>Imagen N&ordm;1:</strong><input type="file" name="imagen1"></td>
                                    <td colspan="2"><strong>Imagen N&ordm;6:</strong><input type="file" name="imagen6"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><strong>Imagen N&ordm;2:</strong><input type="file" name="imagen2"></td>
                                    <td colspan="2"><strong>Imagen N&ordm;7:</strong><input type="file" name="imagen7"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><strong>Imagen N&ordm;3:</strong><input type="file" name="imagen3"></td>
                                    <td colspan="2"><strong>Imagen N&ordm;8:</strong><input type="file" name="imagen8"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><strong>Imagen N&ordm;4:</strong><input type="file" name="imagen4"></td>
                                    <td colspan="2"><strong>Imagen N&ordm;9:</strong><input type="file" name="imagen9"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><strong>Imagen N&ordm;5:</strong><input type="file" name="imagen5"></td>
                                    <td colspan="2"><strong>Imagen N&ordm;10:</strong><input type="file" name="imagen10"></td>
                                </tr>
                                <tr>
                                    <td>
                                        <label>
                                            <input type="checkbox" name="nuevo">
                                            Aparecer como nuevo
                                        </label>
                                    </td>
                                    <td>
                                        <label>
                                            <input type="checkbox" name="oferta">
                                            Aparecer en oferta
                                        </label>
                                    </td>
                                    <td colspan="2">Observaciones: 
                                        <textarea name="observaciones"></textarea></td>
                                </tr>
                                <tr>
                                    <td colspan="4"><input type="submit" id="submit" class="secondary-nav small radius button" value="Guardar"> <input type="reset" id="reset" class="secondary small radius button" value="Limpiar"></td>
                                </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function() {
        $('.check').click(function() {
            var $checkboxes = $(this).parents('.vehiculo').find('input[type=checkbox]');
            $checkboxes.prop('checked', $(this).is(':checked') ? true : false);
        });
        $('#carroceria').change(function() {
            window.location = 'agregarVehiculo?c=' + $(this).val();
        });
        $('form').submit(function() {
            //alert($(this).serialize());
            //return false;
        });
    })
</script>